home *** CD-ROM | disk | FTP | other *** search
/ ftp.cse.unsw.edu.au / 2014.06.ftp.cse.unsw.edu.au.tar / ftp.cse.unsw.edu.au / pub / doc / papers / misc / A System V Compatible Implementation of 4.2BSD Job Control.ms.Z / A System V Compatible Implementation of 4.2BSD Job Control.ms
Encoding:
Text File  |  1992-10-18  |  52.4 KB  |  1,201 lines

  1. .de PB
  2. .sp 1
  3. .RS
  4. .nf
  5. ..
  6. .de PE
  7. .fi
  8. .RE
  9. .sp 1
  10. ..
  11. .DA
  12. .    \" Put page numbers at bottom center rather than top center
  13. .rm CH
  14. .ds CF - \\n(PN -
  15. .    \" UX - UNIX macro
  16. .de UX
  17. .ie \\n(UX \s-1UNIX\s0\\$1
  18. .el \{\
  19. \s-1UNIX\s0\\$1\(dg
  20. .FS
  21. \(dg \s-1UNIX\s0 is a trademark of AT&T.
  22. .FE
  23. .nr UX 1
  24. .\}
  25. ..
  26. .TL
  27. A System V Compatible Implementation of 4.2BSD Job Control
  28. .AU
  29. David C. Lennert
  30. .AI
  31. Hewlett-Packard Company
  32. Information Technology Group
  33. hplabs\^!\^hpda\^!\^davel
  34. .AB
  35. This paper gives an overview of how process groups and controlling
  36. terminals are handled in System V and 4.2BSD and then
  37. discusses the effect 4.2BSD job control has on these things.
  38. A modified 4.2BSD interface is discussed which supports 4.2BSD job control
  39. functionality but in a way which allows AT&T System V compatibility.
  40. This interface has been implemented in Hewlett-Packard's 
  41. .UX
  42. system, HP-UX.
  43. .AE
  44. .sp 1
  45. .NH
  46. INTRODUCTION
  47. .PP
  48. The job control functionality first introduced into
  49. .UX
  50. by Jim Kulp of IIASA and later provided by 4.2BSD
  51. .UX
  52. has become a \fIde facto\fP industry standard.
  53. However, this job control facility, as implemented in 4.2BSD, is incompatible
  54. in several respects with System V.
  55. .PP
  56. Recently a proposal was submitted to the IEEE P1003 Portable Operating
  57. System standard committee by Sun Microsystems [Harris86] which attempts
  58. to define
  59. 4.2BSD job control functionality in a way compatible with System V.
  60. Hewlett-Packard Company has been independently developing a similar
  61. proposal.  HP's proposal is almost identical to Sun's but goes
  62. beyond it to address many "corner case" areas which strongly affect
  63. System V compatibility.
  64. .PP
  65. This paper gives an overview of the relevant areas of System V 
  66. functionality which are affected.  It then overviews how job control
  67. is implemented in 4.2BSD and how this impacts the System V interface.
  68. Finally, the HP-UX interface is presented and a similar overview of its
  69. implementation is given.
  70. .PP
  71. The various overviews cover how job control signals are generated, passed,
  72. and acknowledged by the tty driver and user processes.  They also explain
  73. how process groups are established and changed.
  74. .sp 1
  75. .NH
  76. FUNDAMENTALS
  77. .PP
  78. In the following discussion the reader is assumed to have an understanding
  79. of several fundamental concepts found in the
  80. .UX
  81. operating system.  For convenience these concepts are briefly reviewed here.
  82. .NH 2
  83. Process Groups and Controlling Terminals
  84. .PP
  85. Every process has a unique numeric value associated with it called
  86. its \fIprocess ID\fP.  Every process also has a non-unique numeric value
  87. associated with it called its \fIprocess group ID\fP.
  88. A \fIprocess group\fP is a collection of processes having identical numeric
  89. process group ID's.  Typically, one process in the process group will
  90. be the \fIprocess group leader\fP.  The process group leader has a process ID
  91. which is numerically equal to the process group ID associated with all processes
  92. in the process group.  Typically, the process group leader is the ancestor
  93. of all other processes in the process group.
  94. .PP
  95. A process can have a \fIcontrolling terminal\fP which is usually the login
  96. terminal of the user who created the process.  A process can obtain access
  97. to its controlling terminal by opening the file \fI/dev/tty\fP.
  98. All processes in the same process group typically share the same controlling
  99. terminal.  A terminal usually has a process group ID associated with it,
  100. called the \fItty group ID\fP.  When a user generates a keyboard signal
  101. (e.g., by typing the interrupt character), the tty driver sends the appropriate
  102. signal to all processes which are members of the process group indicated by
  103. the tty group ID.
  104. In summary,
  105. usually, but not necessarily, all processes in the same process group share
  106. the same controlling terminal, and the tty group ID for that terminal is
  107. equal to the process group ID of the process group.
  108. .PP
  109. For further explanation see [Roch85] and intro(2) in your favorite
  110. .UX
  111. Programmer's Manual.
  112. .NH 2
  113. 4.2BSD Job Control
  114. .PP
  115. 4.2BSD job control allows users to selectively stop (suspend) the
  116. execution of processes and continue (resume) their execution at any
  117. later point.  This only easily works for processes which are stopped
  118. and continued during the same login session.
  119. .PP
  120. The user almost always employs this facility via the interactive interface
  121. jointly supplied by the system tty driver and a job control shell such as
  122. csh(1) or ksh(1).
  123. The tty driver recognizes a user-defined
  124. \fIsuspend character\fP which causes all current foreground processes to
  125. stop and the user's job control shell to resume.
  126. The job control shell provides commands which continue stopped processes
  127. in either the foreground or background.
  128. The tty driver will also stop a background process when it attempts to
  129. read from or write to the users terminal.  This allows the user to finish
  130. or suspend their foreground task without interruption and continue the
  131. stopped background process at a more convenient time.
  132. .PP
  133. To enable the system to support this,
  134. 4.2BSD job control introduces five new signals: SIGSTOP, SIGTSTP, SIGTTIN,
  135. SIGTTOU, and SIGCONT.  The first four signals cause a process to stop unless
  136. the signals are being caught or ignored.  SIGCONT always causes a stopped
  137. process to continue.  (SIGCONT has no effect on processes which are not
  138. stopped.)  SIGSTOP cannot be caught or ignored.
  139. .PP
  140. The tty driver sends some of these signals to all processes in the tty
  141. process group under the following conditions:  The driver sends SIGTSTP when
  142. the user types the suspend or delayed suspend character.  The driver sends
  143. SIGTTIN (SIGTTOU) when a background process attempts to read from (write to)
  144. its controlling terminal.
  145. SIGCONT is usually only sent by a job control shell when
  146. the user requests that a stopped process be continued.
  147. Of course, any signal can be sent by a user via the kill(1) command or
  148. by a program via the kill(2) system call.
  149. .PP
  150. It should be noted that these signals can be added to a
  151. .UX
  152. implementation in a manner which preserves source and object code
  153. compatibility.  A process is not required to be aware of them.  By
  154. default the signals do "the right thing."
  155. .PP
  156. For further information see [Joy80] and [UCB83].
  157. .sp 1
  158. .NH
  159. AT&T SYSTEM V
  160. .NH 2
  161. Introduction
  162. .PP
  163. System V process groups closely resemble the concept of a login session.
  164. That is, all processes spawned during the same login session tend to
  165. belong to the same process group, and keyboard signals are typically
  166. sent to all processes spawned from the login session.
  167. .NH 2
  168. System V Process Group Handling
  169. .PP
  170. In System V, the only way to alter the process group associated
  171. with a process (p_pgrp) is via setpgrp(2).  And this can only set the process
  172. group to equal the process ID (pid) of the process.  When this happens
  173. the resulting process with pid = p_pgrp is called a process group leader.
  174. Since a process's pid can never change,
  175. once a process issues a setpgrp(2) call it irrevocably becomes
  176. a process group leader.
  177. .PP
  178. The init(1M) process spawns all other processes on the system either
  179. directly or indirectly.  Before directly spawning a process
  180. (after the fork(2) but before the exec(2)),
  181. init calls setpgrp(2).
  182. Thus all original children (not orphans) of init are forced to (irrevocably)
  183. be process group leaders.
  184. .PP
  185. When a new process is created, it is assigned a new pid but it inherits
  186. the process group number of its parent.  Thus child processes are, by
  187. default, not process group leaders (although they can become a process
  188. group leader via setpgrp(2)).
  189. .PP
  190. When a process group leader which has a controlling terminal (see below)
  191. terminates, SIGHUP is sent to all processes in the same
  192. process group.
  193. .PP
  194. Further, when a process group leader terminates, all processes that
  195. belong to this process group are altered to belong to no process group
  196. (their p_pgrp is set to zero).
  197. More precisely, when any process exits, all processes whose process
  198. group (p_pgrp) equals the pid of the terminating process will have their
  199. p_pgrp set to zero; this check succeeds only in the case of a
  200. terminating process group leader.
  201. .NH 2
  202. System V Controlling Terminals
  203. .PP
  204. A terminal that is currently open by a process may also be a "controlling
  205. terminal" for a process group.  When certain
  206. control characters are typed on a controlling terminal, signals are 
  207. sent by the terminal driver to all processes that belong to the process
  208. group associated with the terminal.
  209. .PP
  210. When a process becomes a process group leader (via setpgrp(2)) it
  211. automatically loses its controlling terminal.  After this,
  212. the first terminal (that is not already a controlling terminal)
  213. opened by the process
  214. is assigned to be the controlling terminal for that process.
  215. Also, the process group associated with that terminal (t_pgrp, also known
  216. as the tty group ID) is set
  217. equal to the process group associated with the process group leader
  218. (p_pgrp).
  219. All child processes inherit the controlling terminal and
  220. process group of their parent.
  221. .PP
  222. More precisely, in System V, the process group associated with a 
  223. terminal (t_pgrp), can be changed in the following ways:
  224. .IP (1)
  225. When a terminal is opened by a process group leader (pid == p_pgrp)
  226. that does not already have a controlling terminal,
  227. it becomes the controlling terminal for that process group 
  228. (t_pgrp is set equal to p_pgrp) if it is not already a controlling
  229. terminal.
  230. .IP (2)
  231. When a process group leader (pid == p_pgrp) dies, if it has a 
  232. controlling terminal that is associated with the same process
  233. group (t_pgrp == p_pgrp), then that terminal is disassociated from that
  234. process group (t_pgrp is set to zero).
  235. .IP (3)
  236. When the last process to have a terminal open closes that terminal,
  237. the terminal is disassociated from its process group (t_pgrp
  238. is set to zero).
  239. .NH 2
  240. System V Typical Scenario
  241. .PP
  242. This is a typical scenario for the birth and death of a process group and
  243. its controlling terminal.
  244. .PP
  245. The init(1M) process wants to enable a terminal for login.  It calls fork(2)
  246. to create a new process and then calls
  247. setpgrp(2) to make the process a process
  248. group leader which also removes the process's controlling terminal.  It
  249. then runs the getty(1M) program as the process via exec(2).
  250. Getty opens the terminal causing it to become getty's controlling terminal
  251. and be associated with getty's process group (t_pgrp is set to p_pgrp).
  252. Getty replaces itself with login(1) which replaces itself with a login
  253. shell, e.g., sh(1).
  254. Usually no program calls setpgrp(2) and thus all descendent processes
  255. of the login shell are in the same process group and have the same
  256. controlling terminal; keyboard signals are sent to all processes launched
  257. during this session.
  258. .PP
  259. When a logout occurs, the login shell (which is the process group leader) 
  260. dies and the controlling terminal is freed up (t_pgrp is set to zero) so
  261. that it can be claimed as a controlling terminal by a subsequent getty 
  262. respawned by init.
  263. SIGHUP is sent to all processes in the same process group.
  264. The process group (p_pgrp) of all descendent processes is then set to zero.
  265. .PP
  266. Note that there may continue to be background processes (previously
  267. started by the
  268. now defunct login shell) which continue to execute but
  269. keyboard signals will no longer be sent to these processes (since
  270. both t_pgrp and p_pgrp equal zero).
  271. .sp 1
  272. .NH
  273. 4.2BSD
  274. .NH 2
  275. Introduction
  276. .PP
  277. 4.2BSD process groups closely resemble the concept of a task within
  278. a login session, where a task represents a set of processes which
  279. are affected as a group by job control operations.
  280. Every time a job control shell (e.g., csh) spawns either a foreground
  281. or background command, all processes in the pipeline (and their
  282. descendents) are placed in their own unique process group with the
  283. first command in the pipeline being the process group leader.
  284. .PP
  285. A task is in the foreground when the process group associated with the
  286. controlling terminal for the task (t_pgrp) is equal to the process
  287. group associated with the processes in the task (p_pgrp).  
  288. Otherwise the task is in the background.
  289. A job control shell moves a job between the foreground and background
  290. by adjusting the terminal process group (t_pgrp) of the controlling
  291. terminal.
  292. .PP
  293. Note that 4.2BSD forms new process groups with process group leaders
  294. much more often than System V usually does (every command versus
  295. every login).
  296. .NH 2
  297. 4.2BSD Process Group Handling
  298. .PP
  299. In 4.2BSD, the process group associated with a process (p_pgrp)
  300. can be altered in two ways.  The first is via setpgrp(2).  4.2BSD's setpgrp(2)
  301. is analogous to System V's setpgrp(2) except that the former can affect
  302. processes other than the current process and can cause the affected
  303. process to adopt a process group other than that process's process ID (pid).
  304. Thus, unlike System V, a process can cease to be a process group leader.
  305. .PP
  306. In addition to setpgrp(2), a process that is not a member of any
  307. process group (p_pgrp == 0) will "inherit" or join the process
  308. group associated with its controlling terminal at the time the
  309. process is assigned a controlling terminal during open(2).
  310. If the terminal being opened is not presently the controlling
  311. terminal for any process group, then the process opening the
  312. terminal will first be made a process group leader (p_pgrp will
  313. be set to p_pid) and then the terminal will become the controlling
  314. terminal for this new process group.  All this is done by the
  315. tty open code.
  316. .PP
  317. When a new process is created it inherits the process group of its parent.
  318. .PP
  319. Unlike System V init(1M), 4.2BSD init(8) does not call setpgrp(2) when spawning
  320. other processes.  All processes spawned by init inherit init's process
  321. group which happens to be zero ("not a member of any process group").
  322. This is actually crucial for assigning controlling terminals; see below.
  323. .NH 2
  324. 4.2BSD Controlling Terminals
  325. .PP
  326. Unlike System V, a 4.2BSD process does not lose its controlling terminal
  327. when altering its process group (via setpgrp(2)).
  328. Also unlike System V, a 4.2BSD process that is a process group leader
  329. (pid == p_pgrp) but which has no controlling terminal does not receive
  330. a controlling terminal when opening a new terminal.
  331. .PP
  332. A process can obtain a controlling terminal under 4.2BSD in only the
  333. following ways:
  334. .IP (1)
  335. A process can inherit a controlling terminal from its parent.
  336. .IP (2)
  337. A process that is not a member of any process group (p_pgrp == 0)
  338. can open any terminal and that terminal will become its controlling
  339. terminal (whether or not it is already the controlling terminal for another
  340. process).
  341. However, this can happen in one of two ways:
  342. .IP
  343. If the terminal is not already a controlling terminal (t_pgrp == 0)
  344. then the opening process becomes a process group leader (its p_pgrp is set
  345. equal to its pid) and the terminal becomes its controlling terminal
  346. (t_pgrp is set to the new p_pgrp value).
  347. .IP
  348. If the terminal is already a controlling terminal for another process
  349. (t_pgrp is not zero) then the opening process joins the process group
  350. already associated with the controlling terminal.  That is, p_pgrp is
  351. set equal to the current t_pgrp.  Note that the opening process does
  352. not become a process group leader, i.e., p_pgrp is not equal to its pid.
  353. .IP
  354. Note that this procedure only happens during the first terminal open
  355. for a process that was either originally spawned by init or whose
  356. ancestor processes (all the way back to init) never altered their
  357. process group (p_pgrp) either by opening a terminal or calling setpgrp(2).
  358. .PP
  359. A terminal ceases to be a controlling terminal (t_pgrp is set to zero) under
  360. 4.2BSD in the following way:
  361. .IP (1)
  362. When the last process to have a terminal open closes that terminal
  363. then the terminal is disassociated from its process group (t_pgrp
  364. is set to zero).
  365. .PP
  366. There are two other facilities unique to 4.2BSD which affect access to
  367. control terminals: the TIOCSPGRP ioctl(2) and vhangup(2).
  368. .PP
  369. The TIOCSPGRP ioctl(2) function changes a terminal's process group (t_pgrp)
  370. to any desired value.
  371. It is typically used by csh(1) to control which set of processes (process
  372. group) is in the foreground.
  373. .PP
  374. The vhangup(2) function is invoked by init after
  375. forking but before exec'ing getty.  This function removes read and
  376. write permission for all processes (including the caller)
  377. that have the controlling terminal
  378. open (whether or not it is their controlling terminal).  It then sends
  379. SIGHUP to the process group associated with the terminal (t_pgrp).
  380. The latter action is similar to the System V functionality that sends
  381. SIGHUP to a process group on death of the process group leader; 4.2BSD
  382. does not do this on the death of a process group leader.
  383. .NH 2
  384. 4.2BSD Typical Scenario
  385. .PP
  386. This is a typical scenario for the birth and death of a login, its
  387. controlling terminal, and process groups associated with a job.
  388. .PP
  389. The init(8) process wants to enable a terminal for login.
  390. First it creates a new process via fork(2).
  391. Then it opens the terminal which
  392. (because the p_pgrp inherited from init is zero)
  393. causes it to become the controlling
  394. terminal for this process and either alters the process group (p_pgrp) of
  395. the process to match the terminal process group (t_pgrp) if non-zero, or
  396. alters both p_pgrp and t_pgrp to equal the process ID (pid) if t_pgrp is zero.
  397. At this point the new process has a controlling terminal whose process group
  398. (t_pgrp) is equal to the process's process group (p_pgrp).  However, the 
  399. process may not be a process group leader (i.e., p_pgrp may not equal pid).
  400. .PP
  401. Now the new process calls vhangup(2) to remove
  402. access permissions for the controlling terminal from all processes (as well
  403. as sending SIGHUP to any processes in the process group previously
  404. associated with the terminal).
  405. The new process then reopens the terminal to get a file descriptor with
  406. read and 
  407. write permissions since the vhangup(2) removed these permission from the
  408. file descriptor returned by the previous open.
  409. The previous file descriptor is not closed until now to prevent losing
  410. the controlling terminal; (remember that p_pgrp for the new process is
  411. no longer zero.)
  412. .PP
  413. The new process now replaces itself with getty(8) which replaces itself
  414. with login(1) which replaces itself with a login shell, e.g., csh(1).
  415. Csh now begins to manipulate the process group associated with the
  416. terminal (t_pgrp) via the TIOCSPGRP and TIOCGPGRP ioctl(2) calls and
  417. the process group associated with its child processes (p_pgrp) via
  418. setpgrp(2) in order to allow job control.  This happens (briefly) in the
  419. following way:
  420. .PP
  421. Csh launches a pipeline by making all programs in the pipeline be
  422. immediate descendents of csh.  (This is different from sh which makes
  423. all programs in the pipeline except the last be descendents of the
  424. last program in the pipeline.)
  425. All programs in the pipeline belong to the same process group (not the
  426. same as csh's process group) and the first program in the pipeline is
  427. the process group leader (its pid is equal to the process group for the
  428. pipeline).
  429. If the pipeline is being launched in the foreground (or moved to the
  430. foreground) then the process group associated with the terminal (t_pgrp)
  431. is set to the process group of the pipeline.
  432. .PP
  433. When a logout occurs, the login shell dies.
  434. Any pending SIGTTIN, SIGTTOU, and SIGTSTP signals are cleared for all 
  435. descendent processes.
  436. All immediate child processes are inherited as orphans by init; if any are
  437. currently stopped then they are killed (SIGKILL).
  438. If the exiting process is the last process that has the controlling 
  439. terminal open then the terminal's process group (t_pgrp) is set to zero,
  440. otherwise it is left alone.
  441. Nothing special is done for process group leaders; in fact, login shells
  442. are frequently not process group leaders.  (SIGHUP is not sent and the
  443. controlling terminal is not necessarily cleared.)
  444. .PP
  445. Note that there may continue to be processes (previously
  446. started by the now defunct login shell) which continue to execute.
  447. And that keyboard signals can still be sent to these processes under some
  448. circumstances (specifically when the processes were in the foreground
  449. (p_pgrp == t_pgrp) when the login shell died; this usually only happens
  450. when the login shell is killed from another terminal via kill(1).)
  451. Note also that this continues to be true even after a new session logs in
  452. on the same terminal since the new login shell joins the process group
  453. which is already associated with the terminal from the prior login.
  454. .NH 2
  455. Job Control Signal Handling
  456. .PP
  457. The following discussions concerning signals and kernel process
  458. synchronization are similar to ones found in [Thom78], [Ritch79],
  459. and [Bach79].
  460. .NH 3
  461. Basic Overview
  462. .PP
  463. Usually a process is either running or sleeping waiting for an event to
  464. occur (e.g., I/O completion).  When a signal is sent to a process (either
  465. by another process or an I/O driver) what actually occurs is that a flag
  466. is set for the receiving (or target) process indicating that the signal
  467. has been sent and the target process performs the actual signal operation
  468. to itself the next time it runs.  Thus sending a signal amounts to
  469. requesting the target process to itself perform a particular action.
  470. If the target process is already running it is interrupted to process
  471. the signal.  If it is runnable but not currently running then the
  472. system merely waits for it to become the currently running process at
  473. which point the signal is acknowledged.  If the target process
  474. is sleeping then either
  475. it is moved into a runnable state (if it is sleeping at an "interruptable"
  476. priority) or it is left sleeping (at an "uninterruptable" priority) and
  477. the signal is not acknowledged until the slept on event occurs.
  478. .PP
  479. The kernel procedure which sends a signal is psignal() and is executed
  480. by the sending process or driver.
  481. Psignal() updates a list of pending signals for the receiving process.
  482. If the receiving process is the currently running process and it is
  483. executing in kernel mode then the pending signal is acknowledged
  484. when the current system call completes.
  485. (This is the case where the sending process and the receiving process
  486. are the same.)
  487. If the receiving process is the currently running process and it is
  488. executing in user mode then a special event is generated
  489. which causes the process to
  490. enter the kernel and acknowledge the pending signal.
  491. (This is the case where the sending "process" is really an interrupt
  492. handler which, for example, is servicing an interrupt character
  493. typed on a user's terminal.)
  494. If the receiving process is
  495. sleeping but not holding off signals then it is set running via wakeup();
  496. the pending signal is acknowledged as soon as the receiving process executes.
  497. If the receiving process is suspended in a sleep state that holds off
  498. signals ("sleeping uninterruptably") then it is left sleeping;
  499. the pending signal will be acknowledged after the waited for event occurs.
  500. .PP
  501. The procedure which tests for a pending signal is issig() and is executed
  502. by the receiving process.
  503. Issig() is executed whenever the receiving process changes from kernel
  504. mode to user mode execution; for example, at the completion of a system call.
  505. It is also executed whenever the receiving process is awakened from
  506. being suspended in a sleep state that does not hold off signals ("sleeping
  507. interruptably").
  508. .PP
  509. The procedure which performs the requested signal operation (e.g.,
  510. invoking a signal handler or killing the process) is psig() and is
  511. executed by the receiving process if issig() returns true.
  512. .PP
  513. This basic structure is essentially the same in System V, 4.2BSD, and
  514. HP-UX.  However, under 4.2BSD-style job control, these general principles
  515. can work slightly differently:
  516. .PP
  517. When processing stop signals,
  518. the psignal() function, called by the sending process, actually stops 
  519. the target process sometimes.  In these cases, the target process
  520. never realizes that it received the signal or that it stopped.  
  521. However, in other cases, psignal() performs the usual process of 
  522. setting the flag (p_sig) requesting
  523. that the target process stop itself the next time it runs.
  524. .PP
  525. The issig() function, called by the target process, can actually stop the
  526. target process.
  527. .PP
  528. The psig() function is only called in the case where a user handler
  529. has been provided for the job control signal.
  530. .PP
  531. A more complete description of job control signal handling is contained
  532. in the pseudocode below.
  533. .NH 3
  534. psignal()
  535. .PP
  536. To send SIGCONT to a target process:
  537. .PB
  538. sending SIGCONT clears any pending stop signals;
  539. if the target process is STOPPED but is also SLEEPING (p_wchan != 0)
  540.     merely continue the process's SLEEP;
  541.  
  542. else if the target process is STOPPED and is NOT SLEEPING (p_wchan == 0)
  543.     set the process RUNNING;
  544. .PE
  545. .PP
  546. To send a stop signal (SIGTSTP, SIGTTIN, SIGTTOU, SIGSTOP) to a target process:
  547. .PB
  548. sending a stop signal clears any pending SIGCONT;
  549.  
  550. if the target process is RUNNABLE or RUNNING
  551.     note the pending signal in p_sig;
  552.  
  553. else if the target process is SLEEPING NON-interruptably
  554.     note the pending signal in p_sig;
  555.  
  556. else if the target process is SLEEPING interruptably
  557.      and IS catching the signal
  558.     note the pending signal in p_sig and
  559.     wakeup the process from its sleep;
  560.  
  561. else if the target process is SLEEPING interruptably
  562.      and is NOT catching the signal
  563.     stop the process by setting its state to SSTOP
  564.     but leave it sleeping on its p_wchan;
  565.     send SIGCLD to parent (if it expects BSD-style)
  566. .PE
  567. .PP
  568. General note: sending a stop signal (other than SIGSTOP) to a child
  569. of init causes the target process to be killed.
  570. .NH 3
  571. issig()
  572. .PP
  573. Issig() is called in all cases except where the process was
  574. sleeping interruptably and was not catching the signal. 
  575. .PP
  576. To acknowledge a pending SIGCONT or stop signal:
  577. .PB
  578. if in the middle of a VFORK
  579.     hold off all stop signals (pretend they don't exist yet)
  580.  
  581. else if catching the signal
  582.     return a request to invoke user signal handler via psig()
  583.  
  584. else if SIGCONT
  585.     do nothing  /* pretend it doesn't exist */
  586.  
  587. else /* stop signals */
  588.     stop the process by setting its state to SSTOP
  589.     send SIGCLD to parent (if it expects BSD-style)
  590.     call swtch() to dispatch another process
  591. .PE
  592. .PP
  593. General note: sending a stop signal (other than SIGSTOP) to a child
  594. of init causes the target process to be killed.
  595. .NH 3
  596. psig()
  597. .PP
  598. Psig() is called whenever issig() returns an indication
  599. that a user handler is defined for a job control signal.
  600. Psig() merely invokes the user signal handler.
  601. .NH 3
  602. wakeup()
  603. .PP
  604. The fact that a process is sleeping (waiting for an event to occur)
  605. is indicated by two process state values:  p_wchan is non-zero,
  606. indicating the event being waited for, and the process state is SSLEEP.
  607. .PP
  608. Wakeup() usually causes all processes waiting (sleeping) on a specified 
  609. event to be awakened.  When a process is awakened two things
  610. happen:  The process is removed from the sleep queue (p_wchan is cleared)
  611. and it is added to the run queue.
  612. .PP
  613. If, however, wakeup() discovers a process whose p_wchan matches the 
  614. specified event but whose process state is SSTOP (stopped) then
  615. the process is removed from the sleep queue (indicating that the
  616. waited for even has happened) but it is not placed on the run queue.
  617. A subsequent SIGCONT will cause it to be placed on the run queue.
  618. .PP
  619. Thus it is possible to have a process which is both sleeping (p_wchan
  620. non-zero) and stopped (process state is SSTOP rather than SSLEEP).
  621. .NH 3
  622. Signal Setup via init
  623. .PP
  624. When init(8) launches any process it causes the process to ignore all
  625. the job control stop signals (SIGTSTP, SIGTTIN, & SIGTTOU).  This allows
  626. login shells which are not job control shells to automatically ignore
  627. the signals.  Further, all descendent processes of such a login shell
  628. will also ignore these signals unless they explicitly enable them.
  629. .NH 2
  630. Foreground/Background Processes
  631. .NH 3
  632. Basic Overview
  633. .PP
  634. 4.2BSD job control supports the notion of a process being in the
  635. .I foreground
  636. or
  637. .I background.
  638. The distinction is a background process is usually forced to stop when
  639. it attempts to perform I/O (including most control operations) on its
  640. controlling terminal, while a foreground process is not hindered.
  641. .PP
  642. Specifically, when a background process attempts to read from its controlling
  643. terminal it is sent the SIGTTIN signal which, by default, causes it to stop.
  644. When it attempts to write to its controlling terminal and LTOSTOP has been
  645. enabled for the terminal, then the process is sent the SIGTTOU signal which,
  646. by default, causes it to stop.
  647. If, however, a background process has chosen to catch the signal, the 
  648. specified user handler is invoked.
  649. If the process is ignoring or masking the stop signal(s), then
  650. the terminal I/O request returns an I/O error, EIO.
  651. .PP
  652. A background process is one whose process group (p_pgrp) is not equal
  653. to the process group of its controlling terminal (t_pgrp) (and t_pgrp
  654. is not zero).  All other processes (including ones doing I/O to terminals
  655. that are not their controlling terminals) are considered to be in the
  656. foreground.
  657. .NH 3
  658. Tty Driver Provisions
  659. .PP
  660. To distinguish between foreground and background
  661. programs the tty driver must perform checks on attempted I/O operations to
  662. a process's controlling terminal.
  663. This is done in several places.
  664. .PP
  665. At the beginning of a read/write system call the tty driver checks
  666. to see if the calling process is in the background.
  667. If it is, then all processes in the
  668. process group of the calling process are sent the appropriate
  669. signal (SIGTTIN or SIGTTOU) unless the signal is masked or ignored
  670. by the calling process.  In this case the driver returns the EIO error.
  671. After the tty driver sends the signal, the calling process is put to
  672. sleep waiting for the \fIlightning bolt event\fP\(dg.
  673. .FS
  674. \(dg The lightning bolt event is a standard
  675. .UX
  676. event which occurs frequently, for example, every second.
  677. .FE
  678. This allows the calling process to receive the signal (and usually stop).
  679. When the process returns from the sleep (usually by being continued) the
  680. tty driver repeats the foreground/background check before proceeding with
  681. the operation.
  682. .PP
  683. When the process is in the foreground, the I/O operation proceeds.
  684. In the case of a terminal read this usually results in the process being
  685. put to sleep to wait for input characters to arrive.
  686. At this point the user could type their suspend character (e.g., ^Z).
  687. This causes the interrupt portion of the tty driver to send SIGTSTP
  688. to the controlling terminal's process group (i.e., all processes which
  689. are in the foreground).  In our scenario this
  690. would include the process sleeping on terminal input, and this would
  691. typically cause it to stop.
  692. .PP
  693. When a sleeping process is stopped it is also left sleeping as well.
  694. If, in this case, tty input characters subsequently arrived then the 
  695. process would
  696. be awakened.  However, because it is also stopped, it would not be
  697. set running; it would merely be "unslept".
  698. .PP
  699. At some later time the process would be continued (e.g., via a csh
  700. "fg" or "bg" command which sends SIGCONT).
  701. If the process had not been previously unslept it would merely continue
  702. its sleeping; it would receive no indication that it had stopped and 
  703. continued.
  704. If the process had been previously unslept it would now be set running.
  705. .PP
  706. When the process is set running it resumes execution in the tty driver.
  707. Because a (potentially substantial) amount of time has elapsed and
  708. because the process may have been stopped and restarted,
  709. the tty driver is no longer sure whether this process is still in
  710. the foreground.
  711. So before checking if input characters are available, the tty driver
  712. rechecks whether the process is in the foreground or background.
  713. This is necessary because, in our
  714. scenario, the stopped process could have been continued in the background
  715. (via csh "bg").  To check this the tty driver merely repeats the
  716. foreground/background check it made at the beginning of the system call.
  717. .sp 1
  718. .NH
  719. SYSTEM V INCOMPATIBILITIES AND THEIR RESOLUTIONS
  720. .PP
  721. Job control as implemented in 4.2BSD is incompatible with System V
  722. semantics in some significant respects.  This section discusses
  723. each of these incompatibilities and the resolution implemented in HP-UX
  724. to maintain System V compatibility.
  725. .PP
  726. The system interface needed to support 4.2BSD-style job control,
  727. tailored for System V compatibility as discussed in this section,
  728. is presented in the form of manual page excerpts in [Len86].
  729. .NH 2
  730. Setpgrp(2) Changes
  731. .PP
  732. Because the needed semantics of 4.2BSD setpgrp(2) conflict with the
  733. semantics of System V setpgrp(2), the 4.2BSD setpgrp(2) function was renamed
  734. to be setpgrp2(2).  (The choice of new name is arbitrary; setpgrp2 was chosen
  735. in the same spirit as 4.2BSD's wait3(2).)
  736. .NH 2
  737. SIGHUP Changes
  738. .PP
  739. System V semantics state that when a process group leader dies, all processes
  740. in the same process group are sent the SIGHUP signal which, by default, kills
  741. all the processes.
  742. .PP
  743. Job control shells execute a command by making all processes in the pipeline
  744. belong to the same (brand new) process group and by making the first program
  745. in the pipeline be the process group leader.  Typically, the first program in a
  746. pipeline terminates before the other programs.  Under System V semantics,
  747. this would cause the premature death of the remaining pipeline.  Because
  748. of this, 4.2BSD does not generate SIGHUP on process group leader death.
  749. .PP
  750. In order to support System V semantics and still allow job control to
  751. function properly, HP-UX makes a distinction between a "System V process
  752. group leader" and a "job control process group leader".  A System V 
  753. process group leader is given System V semantics (SIGHUP is generated)
  754. and a job control process group leader is given 4.2BSD semantics (SIGHUP
  755. is not generated).
  756. A process which becomes a process group leader via setpgrp(2) is considered
  757. to be a System V process group leader.
  758. A process which becomes a process group leader via setpgrp2(2) is considered
  759. to be a job control process group leader.
  760. Since the HP-UX (and System V) init(1M) program calls setpgrp(2) on behalf
  761. of all processes it spawns, all login shells start out as System V process
  762. group leaders.  A process must explicitly call setpgrp2(2) to deviate from
  763. the System V semantics.
  764. .NH 2
  765. SIGCLD Changes
  766. .PP
  767. Under System V, SIGCLD is sent to a process whenever one of its immediate
  768. child processes dies.
  769. Under 4.2BSD, SIGCLD (or its variant, SIGCHLD) is also generated
  770. when a process changes state from running to stopped.
  771. Since a System V application would not expect to receive SIGCLD
  772. under these new circumstances and since a job control shell would
  773. not be able to function properly without such notification, a compatible
  774. compromise was developed.
  775. .PP
  776. The (parent) process wishing to trap SIGCLD may set a flag when calling
  777. the HP-UX sigvector(2)\(dg
  778. .FS
  779. \(dg Sigvector(2) is an HP-UX extension proposed to the IEEE P1003 [Head85]
  780. which supports both the reliable
  781. signal operations of 4.2BSD sigvec(2) and the conventional signal 
  782. operations of System V signal(2).  In HP-UX, signal(2) is implemented
  783. as a library using sigvector(2).
  784. Note that the changes proposed here to sigvector(2) can be identically
  785. made to 4.2BSD sigvec(2).
  786. .FE
  787. \|routine to establish a signal handler.  This flag
  788. will cause SIGCLD to be sent for stopped children, in addition to terminated
  789. children.
  790. A System V application using signal(2) will see the System V compatible
  791. SIGCLD semantics.
  792. .NH 2
  793. Controlling Terminal Changes
  794. .PP
  795. Under System V, whenever a process group leader dies, the controlling terminal
  796. associated with that process group (if any) is deallocated (disassociated from
  797. that process group).
  798. 4.2BSD does not deallocate controlling terminals on process group leader death
  799. for the following reason:
  800. Job control shells make the lead process in every pipeline a process
  801. group leader.  If the controlling terminal for each pipeline were deallocated
  802. whenever the lead process terminated, then the remaining processes would
  803. effectively become background processes (assuming they were currently in
  804. the foreground) and would stop when any of them attempted subsequent I/O to the
  805. terminal.
  806. .PP
  807. To allow both semantics, controlling terminals are only deallocated when
  808. a "System V process group leader" dies and not when a "job control process
  809. group leader" dies.  (See the discussion of SIGHUP changes above.)
  810. .PP
  811. However, this change leads to the following problem:
  812. In order for a terminal to be allocated as a controlling terminal for a 
  813. new login, it must be deallocated when the previous login terminates.
  814. System V relies on process group leader death to deallocate controlling
  815. terminals (since all login shells are forced to be process group leaders
  816. by init(1M)).
  817. This is no longer reliable since login shells could become "job control
  818. process group leaders".  Further, not all logins are spawned directly
  819. by init(1M); the 4.2BSD rlogin facility is a prime example.
  820. 4.2BSD solves this problem by allowing a new login to join the process
  821. group of the controlling terminal which is still allocated from the 
  822. previous login.  However this violates System V compatibility.
  823. .PP
  824. The solution chosen was to mark a process that causes a controlling
  825. terminal to be allocated and to deallocate the controlling terminal
  826. whenever that process terminates.  This reliably catches logins which
  827. are spawned either directly or indirectly from init(1M), whether they are
  828. "System V process group leaders" or not.  Controlling terminals continue
  829. to be deallocated on death of System V process group leaders using the
  830. System V semantics.
  831. .NH 2
  832. Security
  833. .PP
  834. Several security holes exist in the 4.2BSD process group altering
  835. mechanisms.  To plug these holes the following changes were made.
  836. .PP
  837. 4.2BSD setpgrp(2) allows a process to alter the process group associated
  838. with another process to any value.
  839. 4.2BSD restricts this operation so that the
  840. affected process must pass the same security restrictions enforced when
  841. sending signals, or must be a descendent of the calling process.
  842. However, this still allows a process to join a process group
  843. already associated with another user.
  844. To tighten this security, setpgrp2(2) was further restricted such that if the
  845. specified new process group value is equal to the process ID (pid) or
  846. process group ID of any existing processes, then all such processes must
  847. pass the above security restrictions.
  848. .PP
  849. Similarly, the 4.2BSD TIOCSPGRP ioctl(2) allows a terminal's process group
  850. to be altered to any value.  This allows a user's terminal to easily become
  851. an additional "controlling terminal" for another user's process group;
  852. keyboard signals can be sent to the other user's processes, thus bypassing
  853. the security enforced by kill(2).
  854. Because of this, the TIOCSPGRP ioctl(2) was altered to enforce similar
  855. security restrictions as setpgrp2(2).
  856. .PP
  857. In System V and 4.2BSD, a process can obtain access to its controlling
  858. terminal by opening the file \fI/dev/tty\fP.  Under System V, processes
  859. left executing after a user's logout are allowed further access to
  860. \fI/dev/tty\fP until the terminal it represents is reallocated as a
  861. controlling terminal for a new login.  More specifically, \fI/dev/tty\fP
  862. access is allowed whenever the process group ID of the leftover process
  863. matches the process group ID of the terminal.  These IDs continue to match
  864. immediately after logout (since both have been zeroed) until the terminal
  865. is re-enabled for login by getty(1M).  (Note that when the new login
  866. terminates, \fI/dev/tty\fP access is restored again to these prior processes
  867. because the controlling terminal's process group ID is re-zeroed.)  Further,
  868. if a process has its controlling terminal opened directly (not
  869. via the \fI/dev/tty\fP synonym) then access is not restricted at all after
  870. logout.
  871. These System V semantics can constitute security problems.  However, they
  872. are not explicitly required by the System V Interface Definition [ATT86].
  873. .PP
  874. 4.2BSD does nothing to hamper \fI/dev/tty\fP access for processes remaining
  875. after logout.  The process group ID for the controlling terminal is not
  876. altered, and, in fact, it is preserved even into the next login (since
  877. subsequent logins join the already existing process group associated with the
  878. terminal, if any).  These semantics also represent security problems.
  879. However, 4.2BSD does prohibit access to the controlling terminal if it
  880. is opened directly; this is accomplished when init(8) issues the vhangup(2)
  881. system call.
  882. .PP
  883. Although preserving the System V semantics for controlling terminal access
  884. after logout is not deemed necessary or even recommended, it is easy to do
  885. in the following way.
  886. Whenever a process that allocated a controlling terminal dies, all processes
  887. which share this controlling terminal have their process group ID zeroed.
  888. This is analogous to, and occurs in addition to, the System V behavior of
  889. zeroing the process group ID for all related processes when their process
  890. group leader dies.  \fI/dev/tty\fP checks similar to System V can then
  891. be employed.
  892. .NH 2
  893. TTY Driver Considerations
  894. .PP
  895. For System V compatibility, the suspend and delayed suspend characters
  896. are defaulted to a disabled value (0377).  This means that job control
  897. is "inactive" by default when a user logs on.  The user must explicitly
  898. activate job control by defining either or both of these characters via
  899. stty(1) or some similar interface.
  900. .PP
  901. There should be no problem allowing 4.2BSD-style job control, as modified
  902. here, to co-exist with System V's shell layers job control system.
  903. (See shl(1) and sxt(7) in the System V Release 2 reference manuals.)
  904. .sp 1
  905. .NH
  906. HP-UX
  907. .NH 2
  908. Introduction
  909. .PP
  910. HP-UX process groups are used in two major ways.
  911. .PP
  912. System V process groups closely resemble the concept of a login session.
  913. That is, all processes spawned during the same login session tend to
  914. belong to the same process group, and keyboard signals are typically
  915. sent to all processes spawned from the login session.
  916. .PP
  917. Job control process groups closely resemble the concept of a task within
  918. a login session, where a task represents a set of processes which
  919. are affected as a group by job control operations.
  920. Every time a job control shell (e.g., csh) spawns either a foreground
  921. or background command, all processes in the pipeline (and their
  922. descendents) are placed in their own unique process group with the
  923. first command in the pipeline being the process group leader.
  924. .PP
  925. A task is in the foreground when the process group associated with the
  926. controlling terminal for the task (t_pgrp) is equal to the process
  927. group associated with the processes in the task (p_pgrp).  
  928. Otherwise the task is in the background.
  929. A job control shell moves a job between the foreground and background
  930. by adjusting the terminal process group (t_pgrp) of the controlling
  931. terminal.
  932. .PP
  933. Note that a job control shell forms new process groups with process 
  934. group leaders
  935. much more often than a non-job control (System V) shell usually does
  936. (every command versus every login).
  937. .NH 2
  938. HP-UX Process Group Handling
  939. .PP
  940. In HP-UX, the process group associated with a process (p_pgrp)
  941. can be altered via setpgrp(2) or setpgrp2(2).
  942. .PP
  943. As in System V, setpgrp(2) can only set the process
  944. group to equal the process ID (pid) of the process.  When this happens,
  945. the resulting process with pid = p_pgrp is called a System V process group
  946. leader.
  947. .PP
  948. Setpgrp2(2) is analogous to setpgrp(2) except that it can affect
  949. processes other than the current process and can cause the affected
  950. process to adopt a process group other than that process's process ID (pid).
  951. Setpgrp2(2) also forms job control process groups rather than System V
  952. process groups.
  953. Using setpgrp2(2), the calling process, or certain other processes, can either
  954. become a job control process group leader or can cease to be a process
  955. group leader.
  956. .PP
  957. Because job control process groups are handled slightly differently
  958. by HP-UX than System V process groups, HP-UX marks processes
  959. that are job control process group leaders (i.e., that have
  960. called setpgrp2(2) without subsequently calling setpgrp(2)).
  961. .PP
  962. The init(1M) process spawns all other processes on the system either
  963. directly or indirectly.  Before directly spawning a process
  964. (after the fork(2) but before the exec(2)),
  965. init calls setpgrp(2).
  966. Thus all original children (not orphans) of init are forced to
  967. start out as System V process group leaders.
  968. .PP
  969. When a new process is created, it is assigned a new pid but it inherits
  970. the process group number of its parent.  Thus child processes are, by
  971. default, not process group leaders (although they can become a process
  972. group leader via either setpgrp(2) or setpgrp2(2)).
  973. .PP
  974. When a System V process group leader that has a controlling terminal
  975. (see below) terminates, SIGHUP is sent to all processes in the same
  976. process group.
  977. Further, when a System V process group leader terminates, all processes
  978. which belong to this process group are altered to belong to no process group
  979. (their p_pgrp is set to zero).
  980. .PP
  981. Also, whenever any process that allocated a controlling terminal terminates,
  982. all processes that share this controlling terminal are altered to belong
  983. to no process group (their p_pgrp is set to zero).
  984. .PP
  985. When any process exits, any pending SIGTTIN, SIGTTOU, and SIGTSTP signals
  986. are cleared from all descendent processes (not just immediate children).
  987. .NH 2
  988. HP-UX Controlling Terminals
  989. .PP
  990. A terminal that is currently open by a process may also be a "controlling
  991. terminal" for a process group (collection of processes).  When certain
  992. control characters are typed on a controlling terminal, signals are 
  993. sent by the terminal driver to all processes which belong to the process
  994. group associated with the terminal.  These include the job control suspend
  995. and delayed suspend characters.
  996. .PP
  997. Controlling terminals also play a role in determining whether a process
  998. is in the foreground or background.  See FOREGROUND/BACKGROUND PROCESSES
  999. above.
  1000. .PP
  1001. When a process becomes a System V process group leader (via setpgrp(2)) it
  1002. automatically loses its controlling terminal.
  1003. (This does not happen for a job control process group leader, i.e. when
  1004. calling setpgrp2(2).)
  1005. After this,
  1006. the first terminal (that is not already a controlling terminal)
  1007. opened by a process that is a (System V or job control) process group leader
  1008. is assigned to be the controlling terminal for that process;
  1009. also the process group associated with that terminal (t_pgrp) is set
  1010. equal to the process group associated with the process group leader
  1011. process (p_pgrp).
  1012. All child processes inherit the controlling terminal and
  1013. process group of their parent.
  1014. .PP
  1015. More precisely, in HP-UX, the process group associated with a 
  1016. terminal (t_pgrp), can be changed in the following ways:
  1017. .IP (1)
  1018. When a terminal is opened by a System V or job control
  1019. process group leader (pid == p_pgrp)
  1020. that does not already have a controlling terminal,
  1021. it becomes the controlling terminal for that process group 
  1022. (t_pgrp is set equal to p_pgrp) if it is not already a controlling
  1023. terminal.
  1024. .IP (2)
  1025. When a System V process group leader (pid == p_pgrp) dies, if it has a 
  1026. controlling terminal that is associated with the same process
  1027. group (t_pgrp == p_pgrp), that terminal is disassociated from that
  1028. process group (t_pgrp is set to zero).
  1029. .IP (3)
  1030. When any process dies which originally caused a controlling terminal
  1031. to be created (see (1) above),
  1032. if it still has a controlling terminal,
  1033. that terminal is disassociated from its
  1034. process group (t_pgrp is set to zero).
  1035. .IP (4)
  1036. When the last process to have a terminal open closes that terminal,
  1037. the terminal is disassociated from its process group (t_pgrp
  1038. is set to zero).
  1039. .IP (5)
  1040. The TIOCSPGRP ioctl(2) call can explicitly change a terminal's
  1041. process group (t_pgrp) to any value within certain security restrictions.
  1042. This is used by a job control shell to change which set of processes
  1043. (process group) is in the foreground.
  1044. .NH 2
  1045. HP-UX Typical Scenario
  1046. .PP
  1047. This is a typical scenario for the birth and death of a login, its 
  1048. controlling terminal, and the process groups associated with a job.
  1049. .PP
  1050. The init(1M) process wants to enable a terminal for login.  It creates a
  1051. new process via fork(2) and calls setpgrp(2) to make it a System V process
  1052. group leader which also removes its controlling terminal.  Init then runs
  1053. the getty(1M) program as the process via exec(2).
  1054. Getty opens the terminal causing the terminal to become getty's controlling
  1055. terminal
  1056. and be associated with getty's process group (t_pgrp is set to p_pgrp).
  1057. As a side effect, this process is now marked as having created a controlling
  1058. terminal; when it dies the controlling terminal will be freed for re-use.
  1059. Getty replaces itself with login(1) which replaces itself with a login
  1060. shell.
  1061. .PP
  1062. At this point one of two scenarios typically takes place.  The login shell
  1063. is either a job control shell (e.g., csh(1)) or it is not (e.g., sh(1)).
  1064. .PP
  1065. If the login shell is not a job control shell then things proceed much
  1066. as they do on System V.
  1067. Usually no program calls setpgrp(2) or setpgrp2(2) and thus all 
  1068. descendent processes
  1069. of the login shell are in the same process group and have the same
  1070. controlling terminal; keyboard signals are sent to all processes launched
  1071. during this session.
  1072. .PP
  1073. If the login shell is a job control shell, then job control operations are
  1074. performed.
  1075. Csh begins to manipulate the process group associated with the
  1076. terminal (t_pgrp) via the TIOCSPGRP and TIOCGPGRP ioctl(2) calls and
  1077. the process group associated with its child processes (p_pgrp) via
  1078. setpgrp2(2) in order to allow job control.  This happens (briefly) in the
  1079. following way:
  1080. .PP
  1081. Csh launches a pipeline by making all programs in the pipeline be
  1082. immediate descendents of csh.  (This is different from sh which makes
  1083. all programs in the pipeline except the last be descendents of the
  1084. last program in the pipeline.)
  1085. All programs in the pipeline belong to the same process group (not the
  1086. same as csh's process group) and the first program in the pipeline is
  1087. the process group leader (its pid is equal to the process group for the
  1088. pipeline).  This process is specially marked as a job control process
  1089. group leader since it was established via setpgrp2(2); this basically
  1090. prevents SIGHUP from being sent to the pipeline when the lead process dies.
  1091. If the pipeline is being launched in the foreground (or moved to the
  1092. foreground) then the process group associated with the terminal (t_pgrp)
  1093. is set to the process group of the pipeline via the TIOCSPGRP ioctl(2).
  1094. .PP
  1095. When a logout occurs, the login shell dies.
  1096. Any pending SIGTTIN, SIGTTOU, and SIGTSTP signals are cleared for all 
  1097. descendent processes.
  1098. All immediate child processes are inherited as orphans by init; if any are
  1099. currently stopped then they are killed (SIGKILL).
  1100. Since the login shell (actually the getty before it was overlaid) created
  1101. a controlling terminal, the controlling terminal is now freed (t_pgrp
  1102. is set to zero) so that it can be claimed as a controlling terminal by
  1103. a subsequent getty respawned by init; also, all processes which share
  1104. this controlling terminal have their process group (p_pgrp) set to zero.
  1105. .PP
  1106. When a logout occurs and
  1107. the login shell is a System V process group leader, SIGHUP is sent
  1108. to all processes in the same process group, and the process group (p_pgrp)
  1109. of all descendent processes is set to zero.
  1110. .PP
  1111. Note that there may continue to be background processes (previously
  1112. started by the
  1113. now defunct login shell) which continue to execute but
  1114. keyboard signals will no longer be sent to these processes (since
  1115. both t_pgrp and p_pgrp equal zero).
  1116. .sp 1
  1117. .NH
  1118. ACKNOWLEDGEMENTS
  1119. .PP
  1120. The following people from Hewlett-Packard contributed to the interface
  1121. design and implementation of job control for HP-UX:
  1122. Jim Barton,
  1123. Dave Decot,
  1124. Larry Dwyer,
  1125. Jeff Glasson,
  1126. Rita Hanson,
  1127. Stephen Hares,
  1128. Steve Head,
  1129. Bob Lenk,
  1130. John Marvin,
  1131. Dave Mears,
  1132. Peter Notess,
  1133. Arn Schaeffer,
  1134. Eviatar Shafrir.
  1135. .PP
  1136. Guy Harris from Sun Microsystems made many substantive comments and suggestions
  1137. which contributed to the interface design and to this paper.
  1138. .sp 3
  1139. .NH
  1140. REFERENCES
  1141. .IP [ATT86] 15
  1142. \fISystem V Interface Definition\fP, Issue 2, AT&T, 1986.
  1143. .IP [Bach84]
  1144. M. J. Bach and S. J. Buroff, "Multiprocessor 
  1145. .UX
  1146. Operating Systems",
  1147. \fIAT&T Bell Lab. Tech. J.\fP, \fB63,\fP No. 8 (October 1984),
  1148. pp. 1733-1749.
  1149. .IP [Head85]
  1150. Stephen Head and Donn Terry, "Reliable Signals Proposal",
  1151. IEEE P1003 Proposal #P.042, Hewlett-Packard Co., September 11, 1985.
  1152. .IP [Joy80]
  1153. William Joy, "An Introduction to the C Shell",
  1154. Computer Science Division, University of California
  1155. at Berkeley, November 1980.
  1156. .IP [Len86]
  1157. David Lennert, Guy Harris, et. al.,
  1158. "System V Compatible BSD-style Job Control Facilities",
  1159. IEEE P1003 Proposal #P.047, Hewlett-Packard Co. & Sun Microsystems,
  1160. April 9, 1986.
  1161. .IP [Ritch79]
  1162. Dennis M. Ritchie, "The
  1163. .UX
  1164. I/O System",
  1165. \fIUNIX Programmer's Manual\fP, Seventh Edition, Volume 2b,
  1166. Bell Telephone Laboratories, Murray Hill, NJ, January 1979.
  1167. .IP [Roch85]
  1168. Marc J. Rochkind,
  1169. \fIAdvanced
  1170. .UX
  1171. Programming\fP,
  1172. Englewood Cliffs, N.J.: Prentice-Hall, 1985.
  1173. .IP [Harris86]
  1174. Guy Harris, "Notes on Signal, Terminal Interface, and User/Group ID
  1175. Handling Proposals", IEEE P1003 Proposal #P.045, Sun Microsystems,
  1176. January 11, 1986.
  1177. .IP [Thom78]
  1178. K. Thompson, "UNIX Implementation",
  1179. \fIBell System Tech. J.\fP, \fB57,\fP No. 6 (July - August 1978),
  1180. pp. 1931-1946.
  1181. .IP [UCB83]
  1182. \fIUNIX Programmer's Manual\fP, 4.2 Berkeley Software Distribution, Virtual 
  1183. VAX-11 Version, Computer Science Division, University of California
  1184. at Berkeley, August 1983.
  1185. .PP
  1186. .bp
  1187. .DS C
  1188. APPENDIX
  1189.  
  1190. JOB CONTROL MANUAL PAGE EXCERPTS
  1191. .DE
  1192. .PP
  1193. The following pages contain the
  1194. .UX
  1195. manual pages which are effected by adding a System V compatible
  1196. implementation of 4.2BSD job control.  Note that each manual page
  1197. generally contains only that portion of text which differs from the
  1198. System V manual page of the same name.  Sometimes, unchanged text
  1199. is provided for locality reference.  Changed text lines are flagged
  1200. with change bars.
  1201.